/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Listado.java
 *
 * Created on 15-mar-2011, 19:47:07
 */

package es.fpsampayo.fin2006;

import es.fpsampayo.fin2006.gui.forms.CatForm;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author fran
 */
public final class Listado_GUI extends javax.swing.JDialog {

    private int id;
    private int tipoDatos;

    public void setTipoDatos(int tipoDatos) {
        this.tipoDatos = tipoDatos;
    }

    /** Creates new form Listado */
    public Listado_GUI(java.awt.Frame parent, boolean modal, DefaultTableModel modelo) {
        super(parent, modal);
        initComponents();
        /*modelo = new DefaultTableModel(){

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }

        };*/
        jTableListado.setModel(modelo);
        jTableListado.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        //cargarDatos("bien_inmueble");
    }

    private Listado_GUI(JFrame jFrame, boolean b) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTableListado = new javax.swing.JTable();
        btnAceptar = new javax.swing.JButton();
        btnVer = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTableListado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTableListado.setColumnSelectionAllowed(true);
        jScrollPane1.setViewportView(jTableListado);

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        btnVer.setText("Ver");
        btnVer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnVer, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 795, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAceptar, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                    .addComponent(btnVer))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnAceptarActionPerformed

    private void btnVerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerActionPerformed
        // TODO add your handling code here:
        int selectedRow;
        selectedRow = jTableListado.getSelectedRow();
        String id_string = jTableListado.getValueAt(selectedRow, 0).toString();
        id = Integer.parseInt(id_string);
        
        if(tipoDatos == ImportarFichero.IS_PADRON){
            PadronForm bieninmueble = new PadronForm(null, rootPaneCheckingEnabled, id);
            bieninmueble.setLocationRelativeTo(this);
            bieninmueble.setVisible(true);
        }else if (tipoDatos == ImportarFichero.IS_CAT){
            //JOptionPane.showMessageDialog(this, "Función todavía no implementada para formato CAT.\nPerdone las molestias.");
            CatForm cat = new CatForm(null, false, id);
            cat.setLocationRelativeTo(this);
            cat.setVisible(true);
        }else if (tipoDatos == ImportarFichero.IS_FIN2006){
            JOptionPane.showMessageDialog(this, "Función todavía no implementada para formato FIN2006.\nPerdone las molestias.");
        }
    }//GEN-LAST:event_btnVerActionPerformed


    /*public void cargarDatos (){
        try {
            String sql = "SELECT * FROM public.parcelas";
            Conexion conexion = new Conexion();
            ResultSet rs = conexion.Select(sql);
            ResultSetMetaData metadata = rs.getMetaData();
            int ncol = metadata.getColumnCount();
            String campos[] = new String [ncol];
            for ( int i = 0; i < ncol ; i++)
                campos[i] = metadata.getColumnLabel(i+1);
            modelo.setColumnIdentifiers(campos);
            while (rs.next()){
                Object[] fila = new Object[ncol];
                for ( int i = 0; i < ncol; i++){
                    try{
                        fila[i] = rs.getObject(i + 1);
                    } catch (SQLException ex) {
                        Logger.getLogger(Listado_GUI.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                modelo.addRow(fila);
            }
            conexion.Desconectar();

        } catch (SQLException ex) {
            Logger.getLogger(Listado_GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
*/
//    public void cargarDatos (String tabla){
//        try {
//            String sql = "SELECT * FROM public." + tabla;
//            Conexion conexion = new Conexion();
//            ResultSet rs = conexion.Select(sql);
//            ResultSetMetaData metadata = rs.getMetaData();
//            int ncol = metadata.getColumnCount();
//            String campos[] = new String [ncol];
//            for ( int i = 0; i < ncol ; i++)
//                campos[i] = metadata.getColumnLabel(i+1);
//            modelo.setColumnIdentifiers(campos);
//            while (rs.next()){
//                Object[] fila = new Object[ncol];
//                for ( int i = 0; i < ncol; i++){
//                    try{
//                        fila[i] = rs.getObject(i + 1);
//                    } catch (SQLException ex) {
//                        Logger.getLogger(Listado_GUI.class.getName()).log(Level.SEVERE, null, ex);
//                    }
//                }
//                modelo.addRow(fila);
//            }
//
//            conexion.Desconectar();
//
//        } catch (SQLException ex) {
//            Logger.getLogger(Listado_GUI.class.getName()).log(Level.SEVERE, null, ex);
//        }
//    }

//        public void cargarDatos (String concello){
//            Listado_IMP.cargarDatosPadron(concello);
//        /*try {
//            String sql = "SELECT * FROM public." + tabla + " WHERE concello = \'" + concello + "\';";
//            System.out.println(sql);
//            Conexion conexion = new Conexion();
//            ResultSet rs = conexion.Select(sql);
//            ResultSetMetaData metadata = rs.getMetaData();
//            int ncol = metadata.getColumnCount();
//            String campos[] = new String [ncol];
//            for ( int i = 0; i < ncol ; i++)
//                campos[i] = metadata.getColumnLabel(i+1);
//            modelo.setColumnIdentifiers(campos);
//            while (rs.next()){
//                Object[] fila = new Object[ncol];
//                for ( int i = 0; i < ncol; i++){
//                    try{
//                        fila[i] = rs.getObject(i + 1);
//                    } catch (SQLException ex) {
//                        Logger.getLogger(Listado_GUI.class.getName()).log(Level.SEVERE, null, ex);
//                    }
//                }
//                modelo.addRow(fila);
//            }
//
//            conexion.Desconectar();
//
//        } catch (SQLException ex) {
//            Logger.getLogger(Listado_GUI.class.getName()).log(Level.SEVERE, null, ex);
//        }*/
//    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                Listado_GUI dialog = new Listado_GUI(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnVer;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableListado;
    // End of variables declaration//GEN-END:variables

}
